import config from '../../../config';
import { City, Tile } from '../..';
import { Building } from '../Building';
import { SimModule } from './SimModule';

/** 确定网格是否有道路连通的的逻辑 */
export class RoadAccess extends SimModule {

    building: Building;

    enabled = true;

    /** 网格是否连通道路 */
    value: boolean;

    constructor(building: Building) {
        super();
        this.building = building;
    }

    /** 更新状态 */
    simulate(city: City) {
        if (!this.enabled) {
            this.value = true;
        } else {
            const road = city.findTile(
                this.building,
                (tile: Tile) => tile.building?.type === 'road',
                config.modules.roadAccess.searchDistance);
            this.value = (road !== null);
        }
    }
}